package com.xuchaotong.concurrent;

import java.util.concurrent.BrokenBarrierException;
import java.util.concurrent.CyclicBarrier;

public class Mountaineer implements Runnable{
    private CyclicBarrier cyclicBarrier;

    public Mountaineer(CyclicBarrier cyclicBarrier) {
        this.cyclicBarrier = cyclicBarrier;
    }

    @Override
    public void run() {
        System.out.println("登山者["+ Thread.currentThread().getName() +"],正在赶往山脚！");

        try {
            Thread.sleep(3000);

            System.out.println("登山者["+ Thread.currentThread().getName() +"],已经到达山脚下！");
            cyclicBarrier.await();
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (BrokenBarrierException e) {
            e.printStackTrace();
        }
    }
}
